<script setup lang='ts' name="policy-add">
import type { PlusColumn } from 'plus-pro-components'

import { resetPassword } from '@fl/api/joint-api'
import { SubmitBtn } from '@fl/components'
import { cloneDeep } from 'lodash-es'
import { useJointStore } from '@fl/store/modules/joint'

const visible = defineModel<boolean>('visible', { required: true })
const user = defineModel<object>('user', { required: true })
console.log('🚀 ~ user:', user.value)

const jointCard = useJointStore().getJointCardInfo
const form = ref()
const title = ref('重置密码')

// 提交
async function submit() {
    const params = {
        appKey: jointCard.appKey,
        accountUuid: user.value.accountUuid,
    }
    resetPassword(params).then((res) => {
        console.log('res', res)
        if (res) {
            ElMessage.success('操作成功')
            cancel()
        }
    })
}

function cancel() {
    visible.value = false
}

function reset() {
    user.value = {}
    form.value.formInstance.resetFields()
}
</script>

<template>
    <PlusDialog v-model="visible"
                :title="title"
                width="500"
                close-on-press-escape
                :has-footer="false"
                @cancel="cancel"
                @closed="reset"
    >
        <div class="mt-10">
            <!-- <PlusForm ref="form"
                      v-model="state"
                      :columns="columns"
                      :label-width="120"
                      :rules="rules"
                      :has-footer="false"
                      :row-props="{ gutter: 20 }"
            /> -->
            是否确认重置{{ user.userName }}的密码？
        </div>

        <div class="mx-auto mt20 flex justify-center">
            <el-button @click="cancel">
                取消
            </el-button>

            <SubmitBtn type="primary"
                       @click="submit"
            >
                确认
            </SubmitBtn>
        </div>
    </PlusDialog>
</template>
